import http from "./http.js"; //http是二次封装后的axios
import md5 from 'js-md5';

//首页信息
const getHomeInfo=function getHomeInfo(){
	return http.get("/index-infos");
	//获取首页信息的ajax请求,外面需要.then/async awiat
}
//登录
const login=function login(loginName,password){
	return http.post("/user/login",{
		loginName,
		passwordMd5:md5(password)
	})
}

//注册
const register=function register(loginName,password){
	return http.post("/user/register",{
		loginName,
		password
	})
}

//商品详情页信息
const getDetialInfo=function getDetialInfo(id){
	return http.get("/goods/detail/"+id)
}

//获取购物车产品，详细信息----数量（其他供公用---vuex），其他信息
const getCartList=function getCartList() {
  return http.get('/shop-cart')
}

//添加购物车
const addCart=function addCart(options) {
  // options {goodsId,goodsCount}
  return http.post('/shop-cart', options)
}

//删除购物车商品
const deleteCart=function deleteCart(id) {
  return http.delete('/shop-cart/'+id)
}

//导出所有的的请求
export default {
	getHomeInfo,
	login,
	register,
	getDetialInfo,
	getCartList,
	addCart,
	deleteCart
}